<?php
namespace app\common\model;
use think\Db;
use think\Model;
class Comment extends Model
{
    //所有文章评论
    function allcomment($order = 'comment_time desc',$page_size=10)
    {
        $comment=Db::name('comment')->alias('c')->join('user u','c.user_id = u.user_id')->join('content t','c.user_id=t.content_id')->order($order)->paginate($page_size);
        return $comment;
    }
    //发表评论
    function addcomment()
    {
        session_start();
		if(!isset($_SESSION['user'])){
			 echo "<script>alert('请登录');location='/'</script>";
		}
        $id=input('get.id');
        $content=input('post.textarea');
        $data['comment_id'] =$id;
        date_default_timezone_set("Asia/Shanghai");
        $data['comment_time'] = date("Y-m-d H:i:s");
        $data['user_id']=$_SESSION['user'];
        $data['content'] =$content;
        //$data['user'] =$_SESSION['user'];
        $addcomment=$this->insert($data);
        return $addcomment;
    }
    //删除评论
    public function de_pl()
    {
        $id['comment_id']=input('get.id');
        $denew= $this->where($id)->delete();
        return $denew;
    }
}